<template>
  <el-form-item
      label="奖品库存"
      :rules="rules">
    <count-adjust v-model:model-value="countValue" :min="1" show-symbol="+"></count-adjust>
  </el-form-item>
</template>

<script lang="ts" setup>
import {positiveInteger} from "@/utils/commonRegexp";
import {WritableComputedRef} from "vue";

const props = defineProps<{
  modelValue: number
}>()

const emits = defineEmits<{
  (e: "update:model-value", value: number):void
}>()

const countValue:WritableComputedRef<number> = computed({
  get() {
    return props.modelValue
  },
  set(newValue) {
    emits("update:model-value", newValue)
  }
})

const rules = [{
  required: true,
  trigger: 'blur',
  validator(rule: any, value: any, callback: any) {
    if (!positiveInteger.test(countValue + '')) {
      callback(new Error('规格库存不能为空且需为正整数'))
    } else {
      callback()
    }
  }
}]

</script>

<style scoped lang="scss">

</style>
